package com.example.springdemo82;

import com.aop.*;
import com.bean.AnoConfig;
import com.bean.Customer;
import com.bean.CustomerByAnotation;
import com.bean.CustomerConstuctor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class SpringDemo82Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringDemo82Application.class, args);
        ApplicationContext context = new ClassPathXmlApplicationContext("appConfig.xml");
//        Customer customer = (Customer) context.getBean("cu");
//        System.out.println("id = " + customer.getId() + " name = " + customer.getName() +
//                " password=" + customer.getPassword());
//        CustomerConstuctor cctor = (CustomerConstuctor) context.getBean("cuContructor");
//        System.out.println("*********以下是通过构造器方式注入的bean**************");
//        System.out.println("id = " + cctor.getId() + " name = " + cctor.getName() +
//                " password=" + cctor.getPassword());
//
//        System.out.println("以下为基于注解方式装载bean");
//        ApplicationContext con1 = new AnnotationConfigApplicationContext(AnoConfig.class);
//        CustomerByAnotation cAno = con1.getBean(CustomerByAnotation.class);
//        System.out.println("id = " + cAno.getId() + " name = " + cAno.getName() +
//                " password=" + cAno.getPassword());
        //通过xml方式实现的AspectJ
//        UserDao userDao = (UserDao) context.getBean("userImpl");
//        userDao.addUser();
//        userDao.delUser();UserImplByAno
        //通过注解方式实现的AspectJ
        ApplicationContext con2 = new AnnotationConfigApplicationContext(AspectConfig.class);
        UserDaoByAno userDao = con2.getBean(UserDaoByAno.class);
        userDao.addUser1();

    }

}
